<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:c="clr-namespace:ImmlPad.Controls"
  xmlns:a="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"  >

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="\Resources\Brushes.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <Style x:Key="{x:Type Menu}" TargetType="{x:Type Menu}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Menu}">
          <Border CornerRadius="3,3,0,0">
            <StackPanel ClipToBounds="True" Orientation="Horizontal" IsItemsHost="True"/>
          </Border>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- SimpleStyles: ContextMenu -->

  <Style TargetType="{x:Type ContextMenu}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
    <Setter Property="HasDropShadow" Value="True"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type ContextMenu}">
          <Border
            Name="Border"
            Background="Orange"
            BorderBrush="Pink"
            BorderThickness="1" >
            <c:IndexingStackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
          </Border>
          <ControlTemplate.Triggers>
            <Trigger Property="HasDropShadow" Value="true">
              <Setter TargetName="Border" Property="Padding" Value="0,3,0,3"/>
              <Setter TargetName="Border" Property="CornerRadius" Value="4"/>
            </Trigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- SimpleStyles: MenuItem -->

  <Style x:Key="{x:Static MenuItem.SeparatorStyleKey}" TargetType="{x:Type Separator}">
    <Setter Property="SnapsToDevicePixels" Value="True"/>
    <Setter Property="Height" Value="2"/>
    <Setter Property="Margin" Value="0,4,0,4"/>
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type Separator}">
          <StackPanel SnapsToDevicePixels="True" Height="2" >
            <Rectangle Height="1" Fill="#222" />
            <Rectangle Height="2" Fill="#666" />
          </StackPanel>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- TopLevelHeader -->

  <ControlTemplate x:Key="{x:Static MenuItem.TopLevelHeaderTemplateKey}" TargetType="{x:Type MenuItem}">
    <Border Name="Border" >
      <Border.Background>
        <SolidColorBrush Color="#00585858" />
      </Border.Background>
      <Grid>
        <ContentPresenter
          x:Name="Content"
          TextElement.Foreground="#80FFFFFF"
          VerticalAlignment="Center"
          HorizontalAlignment="Center"
          Margin="10,-1,10,1"
          ContentSource="Header"
          RecognizesAccessKey="True" />
        <Popup
          Name="Popup"
          Placement="Bottom"
          IsOpen="{TemplateBinding IsSubmenuOpen}"
          AllowsTransparency="True"
          Focusable="False"
          PopupAnimation="Fade">
          <a:SystemDropShadowChrome CornerRadius="4"  Margin="0,0,5,5">
            <Border
              Name="SubmenuBorder"
              CornerRadius="0,4,4,4"
              SnapsToDevicePixels="True"
              Background="#585858" >
              <c:IndexingStackPanel
                IsItemsHost="True" 
                KeyboardNavigation.DirectionalNavigation="Cycle" />
            </Border>
          </a:SystemDropShadowChrome>
        </Popup>
      </Grid>
    </Border>
    <ControlTemplate.Triggers>

      <Trigger Property="IsHighlighted" Value="true">
        <Setter TargetName="Content" Property="TextElement.Foreground" Value="#FFF" />
        <Setter TargetName="Border" Property="Background">
          <Setter.Value>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <GradientStop Offset="0.0" Color="#909090" />
              <GradientStop Offset="1.0" Color="#505050" />
            </LinearGradientBrush>
          </Setter.Value>
        </Setter>
      </Trigger>
      <Trigger Property="IsSuspendingPopupAnimation" Value="True">
        <Setter TargetName="Popup" Property="PopupAnimation" Value="None" />
      </Trigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsSuspendingPopupAnimation" Value="True" />
          <Condition Property="IsHighlighted" Value="True" />
        </MultiTrigger.Conditions>
        <Setter TargetName="Border" Property="Background">
          <Setter.Value>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <GradientStop Offset="0.0" Color="#909090" />
              <GradientStop Offset="1.0" Color="#505050" />
            </LinearGradientBrush>
          </Setter.Value>
        </Setter>
        <Setter TargetName="Content" Property="TextElement.Foreground" Value="#FFFFFFFF" />
      </MultiTrigger>

    </ControlTemplate.Triggers>
  </ControlTemplate>

  <!-- TopLevelItem -->

  <ControlTemplate x:Key="{x:Static MenuItem.TopLevelItemTemplateKey}" TargetType="{x:Type MenuItem}">
    <Border Name="Border" >
      <Border.Background>
        <SolidColorBrush Color="#00585858" />
      </Border.Background>
      <ContentPresenter
        x:Name="Content"
        TextElement.Foreground="#80FFFFFF"
        VerticalAlignment="Center"
        HorizontalAlignment="Center"
        Margin="10,-1,10,1"
        ContentSource="Header"
        RecognizesAccessKey="True" />
    </Border>
    <ControlTemplate.Triggers>

      <Trigger Property="IsHighlighted" Value="true">
        <Setter TargetName="Content" Property="TextElement.Foreground" Value="#FFF" />
        <Setter TargetName="Border" Property="Background">
          <Setter.Value>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <GradientStop Offset="0.0" Color="#909090" />
              <GradientStop Offset="1.0" Color="#505050" />
            </LinearGradientBrush>
          </Setter.Value>
        </Setter>
      </Trigger>
      <MultiTrigger>
        <MultiTrigger.Conditions>
          <Condition Property="IsSuspendingPopupAnimation" Value="True" />
          <Condition Property="IsHighlighted" Value="True" />
        </MultiTrigger.Conditions>
        <Setter TargetName="Border" Property="Background">
          <Setter.Value>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
              <GradientStop Offset="0.0" Color="#909090" />
              <GradientStop Offset="1.0" Color="#505050" />
            </LinearGradientBrush>
          </Setter.Value>
        </Setter>
        <Setter TargetName="Content" Property="TextElement.Foreground" Value="#FFFFFFFF" />
      </MultiTrigger>

    </ControlTemplate.Triggers>
  </ControlTemplate>

  <!-- SubmenuItem -->

  <ControlTemplate
    x:Key="{x:Static MenuItem.SubmenuItemTemplateKey}"
    TargetType="{x:Type MenuItem}">
    <Border Name="Border" Background="Transparent" >
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
          <ColumnDefinition Width="13"/>
        </Grid.ColumnDefinitions>
        <ContentPresenter
          Name="Icon"
          Margin="6,4,6,4"
          VerticalAlignment="Center"
          HorizontalAlignment="Center"
          ContentSource="Icon"/>
        <Border
          Name="Check"
          Width="13" Height="13"
          Visibility="Collapsed"
          Margin="6,2,6,2"
          Background="Transparent"
          HorizontalAlignment="Center">
          <Path
            Name="CheckMark"
            Width="7" Height="7"
            Visibility="Hidden"
            SnapsToDevicePixels="False"
            Stroke="White"
            StrokeThickness="2"
            Data="M 0 0 L 7 7 M 0 7 L 7 0" />
        </Border>
        <ContentPresenter
          Margin="0,4"
          TextElement.Foreground="#FFF"
          Name="HeaderHost"
          Grid.Column="1"
          ContentSource="Header"
          RecognizesAccessKey="True"/>
        <TextBlock x:Name="InputGestureText"
          TextElement.Foreground="#FFF"
          Grid.Column="2"
          Text="{TemplateBinding InputGestureText}"
          Margin="5,4,0,4"
          DockPanel.Dock="Right" />
      </Grid>
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="Icon" Value="{x:Null}">
        <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
      </Trigger>
      <Trigger Property="IsChecked" Value="true">
        <Setter TargetName="CheckMark" Property="Visibility" Value="Visible"/>
      </Trigger>
      <Trigger Property="IsCheckable" Value="true">
        <Setter TargetName="Check" Property="Visibility" Value="Visible"/>
        <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
      </Trigger>
      <Trigger Property="IsHighlighted" Value="true">
        <Setter TargetName="Border" Property="Background" Value="#707070" />
      </Trigger>
      <Trigger Property="c:IndexingStackPanel.StackLocation" Value="First" >
        <Setter TargetName="Border" Property="CornerRadius" Value="0,4,0,0" />
      </Trigger>
      <Trigger Property="c:IndexingStackPanel.StackLocation" Value="Last" >
        <Setter TargetName="Border" Property="CornerRadius" Value="0,0,4,4" />
      </Trigger>
      <Trigger Property="c:IndexingStackPanel.StackLocation" Value="FirstAndLast" >
        <Setter TargetName="Border" Property="CornerRadius" Value="0,4,4,4" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="false">
        <Setter TargetName="HeaderHost" Property="TextElement.Foreground" Value="#777"/>
        <Setter TargetName="InputGestureText" Property="TextElement.Foreground" Value="#777"/>
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <!-- SubmenuHeader -->

  <ControlTemplate
    x:Key="{x:Static MenuItem.SubmenuHeaderTemplateKey}"
    TargetType="{x:Type MenuItem}">
    <Border Name="Border" >
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" SharedSizeGroup="Icon"/>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" SharedSizeGroup="Shortcut"/>
          <ColumnDefinition Width="20"/>
        </Grid.ColumnDefinitions>
        <ContentPresenter
          Name="Icon"
          Margin="6,0,6,0"
          VerticalAlignment="Center"
          HorizontalAlignment="Center"
          ContentSource="Icon"/>
        <ContentPresenter
          Margin="0,4"
          TextElement.Foreground="#FFF"
          Name="HeaderHost"
          Grid.Column="1"
          ContentSource="Header"
          RecognizesAccessKey="True"/>
        <TextBlock x:Name="InputGestureText"
          TextElement.Foreground="#FFF"
          Grid.Column="2"
          Text="{TemplateBinding InputGestureText}"
          Margin="5,2,2,2"
          DockPanel.Dock="Right"/>
        <Path
          Name="Arrow"
          Margin="4,0,0,0" 
          Grid.Column="3"
          HorizontalAlignment="Left"
          VerticalAlignment="Center"
          Data="M 0 0 L 0 7 L 4 3.5 Z"
          Fill="White" />
        <Popup
          Name="Popup"
          HorizontalOffset="-8" 
          Placement="Right"
          IsOpen="{TemplateBinding IsSubmenuOpen}"
          AllowsTransparency="True"
          Focusable="False"
          PopupAnimation="Fade">
          <a:SystemDropShadowChrome CornerRadius="4"  Margin="0,0,5,5">
            <Border
              Name="SubmenuBorder"
              CornerRadius="4,4,4,4"
              SnapsToDevicePixels="True"
              Background="#585858" >
              <c:IndexingStackPanel
                IsItemsHost="True"
                KeyboardNavigation.DirectionalNavigation="Cycle" />
            </Border>
          </a:SystemDropShadowChrome>
        </Popup>
      </Grid>
    </Border>
    <ControlTemplate.Triggers>
      <Trigger Property="Icon" Value="{x:Null}">
        <Setter TargetName="Icon" Property="Visibility" Value="Hidden"/>
      </Trigger>
      <Trigger Property="IsHighlighted" Value="true">
        <Setter TargetName="Border" Property="Background" Value="#707070" />
      </Trigger>
      <Trigger Property="c:IndexingStackPanel.StackLocation" Value="First" >
        <Setter TargetName="Border" Property="CornerRadius" Value="0,4,0,0" />
      </Trigger>
      <Trigger Property="c:IndexingStackPanel.StackLocation" Value="Last" >
        <Setter TargetName="Border" Property="CornerRadius" Value="0,0,4,4" />
      </Trigger>
      <Trigger Property="c:IndexingStackPanel.StackLocation" Value="FirstAndLast" >
        <Setter TargetName="Border" Property="CornerRadius" Value="0,4,4,4" />
      </Trigger>
      <Trigger Property="IsEnabled" Value="false">
        <Setter TargetName="HeaderHost" Property="TextElement.Foreground" Value="#777"/>
        <Setter TargetName="InputGestureText" Property="TextElement.Foreground" Value="#777"/>
      </Trigger>
    </ControlTemplate.Triggers>
  </ControlTemplate>

  <!-- MenuItem Style -->

  <Style x:Key="{x:Type MenuItem}" TargetType="{x:Type MenuItem}">
    <Setter Property="OverridesDefaultStyle" Value="True"/>
    <Style.Triggers>
      <Trigger Property="Role" Value="TopLevelHeader">
        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelHeaderTemplateKey}}"/>
        <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
      </Trigger>
      <Trigger Property="Role" Value="TopLevelItem">
        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.TopLevelItemTemplateKey}}"/>
      </Trigger>
      <Trigger Property="Role" Value="SubmenuHeader">
        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuHeaderTemplateKey}}"/>
      </Trigger>
      <Trigger Property="Role" Value="SubmenuItem">
        <Setter Property="Template" Value="{StaticResource {x:Static MenuItem.SubmenuItemTemplateKey}}"/>
      </Trigger>
    </Style.Triggers>
  </Style>


</ResourceDictionary>